#include "key.h"
#include <stdio.h>


enum Button_IDs {
	run_stop_btn_id,
	mode_btn_id,
};

struct Button run_stop_btn;
struct Button mode_btn;


uint8_t read_button_GPIO(uint8_t button_id)
{
	uint8_t key_val = 0;
	switch(button_id)
	{
		case run_stop_btn_id:
			key_val = GPIO_ReadInputDataBit(KEY_START_STOP_PORT, KEY_START_STOP_PIN);
            break;
		case mode_btn_id:
			key_val =  GPIO_ReadInputDataBit(KEY_MODE_PORT, KEY_MODE_PIN);
            break;
		default:
			break;
	}
    return key_val;
}

void run_stop_btn_SINGLE_Click_Handler(void* btn)
{
	LOG("get_key_signal->set_upgrade_falg\r\n");
}

void run_stop_btn_DOUBLE_Click_Handler(void* btn)
{
	LOG("key0_DOUBLE_Click_Handler\r\n");
}

void run_stop_btn_LONG_PRESS_HOLD_Handler(void* btn)
{
	LOG("key0_LONG_PRESS_HOLD_Handler\r\n");
}





void mode_btn_SINGLE_Click_Handler(void* btn)
{
	LOG("key1_SINGLE_Click_Handler\r\n");
}

void mode_btn_DOUBLE_Click_Handler(void* btn)
{
	LOG("key1_DOUBLE_Click_Handler\r\n");
}

void mode_btn_LONG_PRESS_START_Handler(void* btn)
{
	LOG("key1_LONG_PRESS_START_Handler\r\n");
}



void btn_init(void)
{
	button_init(&run_stop_btn, read_button_GPIO, 0, run_stop_btn_id);
	button_init(&mode_btn, read_button_GPIO, 0, mode_btn_id);

	button_attach(&run_stop_btn, SINGLE_CLICK,     run_stop_btn_SINGLE_Click_Handler);
	button_attach(&run_stop_btn, DOUBLE_CLICK,     run_stop_btn_DOUBLE_Click_Handler);
	button_attach(&run_stop_btn, LONG_PRESS_HOLD,  run_stop_btn_LONG_PRESS_HOLD_Handler);

	button_attach(&mode_btn, SINGLE_CLICK,     mode_btn_SINGLE_Click_Handler);
	button_attach(&mode_btn, DOUBLE_CLICK,     mode_btn_DOUBLE_Click_Handler);
	button_attach(&mode_btn, LONG_PRESS_START, mode_btn_LONG_PRESS_START_Handler);

	button_start(&run_stop_btn);
	button_start(&mode_btn);
}
